package com.beyond.dao;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

public class JdbcTemplateHelper {
	
	static Logger logger = LoggerFactory.getLogger(JdbcTemplateHelper.class);
	
	@Autowired
	private DataQueryDao queryDao;
	
	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	/**
	 * 获取表的记录数
	 * @param sql
	 * @return
	 */
	public int getSum(String sql){
		return jdbcTemplate.queryForInt(sql);
	}
	
	/**
	 * 获取表所有列名
	 * 获取维度"dimention",获取指标"target"
	 * @param tabName
	 * @return
	 */
	public Map<String,String> getTabColumn(String tabName){
		return queryDao.getColumnName(tabName);
	}
	
	/**
	 * 批量插入数据
	 * @param sql
	 * @return
	 */
	public void save(String[] sql){
		int rsCount = jdbcTemplate.batchUpdate(sql).length;
		logger.info("批量插入数据数："+rsCount);
	}
}
